using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VVAARTE
    {
        public DataRow Convert2VAARTE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryVAARTE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["VASMANDANT"] = " ".PadRight(2 ); 
         dwReturn["VASKOLL"] = " ".PadRight(5 ); 
         dwReturn["VASART"] = " ".PadRight(24 ); 
         dwReturn["VASFARBE"] = " ".PadRight(10 ); 
         dwReturn["VASABNGRP"] = " ".PadRight(3 ); 
         dwReturn["VASKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VASLFDNR"] = " ".PadRight(0 ); 
         dwReturn["VASAENZL"] = " ".PadRight(0 ); 
         dwReturn["VASAENB"] = " ".PadRight(8 ); 
         dwReturn["VASAEND"] = " ".PadRight(0 ); 
         dwReturn["VASNEUB"] = " ".PadRight(8 ); 
         dwReturn["VASNEUD"] = " ".PadRight(0 ); 
         dwReturn["VASEKOLL"] = " ".PadRight(5 ); 
         dwReturn["VASEART"] = " ".PadRight(24 ); 
         dwReturn["VASEFARBE"] = " ".PadRight(10 ); 
         dwReturn["VASEDKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VASEDWERK"] = " ".PadRight(3 ); 
         dwReturn["VASEDABT"] = " ".PadRight(3 ); 
         dwReturn["VASEDART"] = " ".PadRight(20 ); 
         dwReturn["VASEDVAR"] = " ".PadRight(2 ); 
         dwReturn["VASEDESS"] = " ".PadRight(10 ); 
         dwReturn["VASECOL"] = " ".PadRight(10 ); 
         dwReturn["VASEFFARBE"] = " ".PadRight(10 ); 
         dwReturn["VASEBESCH"] = " ".PadRight(10 ); 
         dwReturn["VASEZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["VASDKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["VASDWERK"] = " ".PadRight(3 ); 
         dwReturn["VASDABT"] = " ".PadRight(3 ); 
         dwReturn["VASDART"] = " ".PadRight(20 ); 
         dwReturn["VASDVAR"] = " ".PadRight(2 ); 
         dwReturn["VASDESS"] = " ".PadRight(10 ); 
         dwReturn["VASCOL"] = " ".PadRight(10 ); 
         dwReturn["VASFFARBE"] = " ".PadRight(10 ); 
         dwReturn["VASBESCH"] = " ".PadRight(10 ); 
         dwReturn["VASZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["VASKZ"] = " ".PadRight(1 ); 
         dwReturn["VASPRIO"] = " ".PadRight(2 ); 
         dwReturn["VASBESTD"] = " ".PadRight(1 ); 
         dwReturn["VASDATUM"] = " ".PadRight(8 ); 
         dwReturn["VASBEMERK"] = " ".PadRight(50 ); 
         dwReturn["VGPFILLER"] = " ".PadRight(59 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapVAARTE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveVAARTE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryVAARTE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapVAARTE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertVAARTE(dwLocal, ITXDBVERSION);
            }
            UpdateVAARTE(dwLocal);
        }
        public void InsertVAARTE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO VAARTE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryVAARTE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM VAARTE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM VAARTE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "VAARTE";
            Return = Result;
            return Return;
        }
        public void DeleteVAARTE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM VAARTE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateVAARTE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE VAARTE SET "
                    +"VASMANDANT= :VASMANDANT,"
                    +"VASKOLL= :VASKOLL,"
                    +"VASART= :VASART,"
                    +"VASFARBE= :VASFARBE,"
                    +"VASABNGRP= :VASABNGRP,"
                    +"VASKUNDNR= :VASKUNDNR,"
                    +"VASLFDNR= :VASLFDNR,"
                    +"VASAENZL= :VASAENZL,"
                    +"VASAENB= :VASAENB,"
                    +"VASAEND= :VASAEND,"
                    +"VASNEUB= :VASNEUB,"
                    +"VASNEUD= :VASNEUD,"
                    +"VASEKOLL= :VASEKOLL,"
                    +"VASEART= :VASEART,"
                    +"VASEFARBE= :VASEFARBE,"
                    +"VASEDKUNDNR= :VASEDKUNDNR,"
                    +"VASEDWERK= :VASEDWERK,"
                    +"VASEDABT= :VASEDABT,"
                    +"VASEDART= :VASEDART,"
                    +"VASEDVAR= :VASEDVAR,"
                    +"VASEDESS= :VASEDESS,"
                    +"VASECOL= :VASECOL,"
                    +"VASEFFARBE= :VASEFFARBE,"
                    +"VASEBESCH= :VASEBESCH,"
                    +"VASEZUSTAND= :VASEZUSTAND,"
                    +"VASDKUNDNR= :VASDKUNDNR,"
                    +"VASDWERK= :VASDWERK,"
                    +"VASDABT= :VASDABT,"
                    +"VASDART= :VASDART,"
                    +"VASDVAR= :VASDVAR,"
                    +"VASDESS= :VASDESS,"
                    +"VASCOL= :VASCOL,"
                    +"VASFFARBE= :VASFFARBE,"
                    +"VASBESCH= :VASBESCH,"
                    +"VASZUSTAND= :VASZUSTAND,"
                    +"VASKZ= :VASKZ,"
                    +"VASPRIO= :VASPRIO,"
                    +"VASBESTD= :VASBESTD,"
                    +"VASDATUM= :VASDATUM,"
                    +"VASBEMERK= :VASBEMERK,"
                    +"VGPFILLER= :VGPFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("VASMANDANT", OracleType.NVarChar).Value = dwData["VASMANDANT"].ToString(); 
          or1.Parameters.Add("VASKOLL", OracleType.NVarChar).Value = dwData["VASKOLL"].ToString(); 
          or1.Parameters.Add("VASART", OracleType.NVarChar).Value = dwData["VASART"].ToString(); 
          or1.Parameters.Add("VASFARBE", OracleType.NVarChar).Value = dwData["VASFARBE"].ToString(); 
          or1.Parameters.Add("VASABNGRP", OracleType.NVarChar).Value = dwData["VASABNGRP"].ToString(); 
          or1.Parameters.Add("VASKUNDNR", OracleType.NVarChar).Value = dwData["VASKUNDNR"].ToString(); 
          or1.Parameters.Add("VASLFDNR", OracleType.NVarChar).Value = dwData["VASLFDNR"].ToString(); 
          or1.Parameters.Add("VASAENZL", OracleType.NVarChar).Value = dwData["VASAENZL"].ToString(); 
          or1.Parameters.Add("VASAENB", OracleType.NVarChar).Value = dwData["VASAENB"].ToString(); 
          or1.Parameters.Add("VASAEND", OracleType.NVarChar).Value = dwData["VASAEND"].ToString(); 
          or1.Parameters.Add("VASNEUB", OracleType.NVarChar).Value = dwData["VASNEUB"].ToString(); 
          or1.Parameters.Add("VASNEUD", OracleType.NVarChar).Value = dwData["VASNEUD"].ToString(); 
          or1.Parameters.Add("VASEKOLL", OracleType.NVarChar).Value = dwData["VASEKOLL"].ToString(); 
          or1.Parameters.Add("VASEART", OracleType.NVarChar).Value = dwData["VASEART"].ToString(); 
          or1.Parameters.Add("VASEFARBE", OracleType.NVarChar).Value = dwData["VASEFARBE"].ToString(); 
          or1.Parameters.Add("VASEDKUNDNR", OracleType.NVarChar).Value = dwData["VASEDKUNDNR"].ToString(); 
          or1.Parameters.Add("VASEDWERK", OracleType.NVarChar).Value = dwData["VASEDWERK"].ToString(); 
          or1.Parameters.Add("VASEDABT", OracleType.NVarChar).Value = dwData["VASEDABT"].ToString(); 
          or1.Parameters.Add("VASEDART", OracleType.NVarChar).Value = dwData["VASEDART"].ToString(); 
          or1.Parameters.Add("VASEDVAR", OracleType.NVarChar).Value = dwData["VASEDVAR"].ToString(); 
          or1.Parameters.Add("VASEDESS", OracleType.NVarChar).Value = dwData["VASEDESS"].ToString(); 
          or1.Parameters.Add("VASECOL", OracleType.NVarChar).Value = dwData["VASECOL"].ToString(); 
          or1.Parameters.Add("VASEFFARBE", OracleType.NVarChar).Value = dwData["VASEFFARBE"].ToString(); 
          or1.Parameters.Add("VASEBESCH", OracleType.NVarChar).Value = dwData["VASEBESCH"].ToString(); 
          or1.Parameters.Add("VASEZUSTAND", OracleType.NVarChar).Value = dwData["VASEZUSTAND"].ToString(); 
          or1.Parameters.Add("VASDKUNDNR", OracleType.NVarChar).Value = dwData["VASDKUNDNR"].ToString(); 
          or1.Parameters.Add("VASDWERK", OracleType.NVarChar).Value = dwData["VASDWERK"].ToString(); 
          or1.Parameters.Add("VASDABT", OracleType.NVarChar).Value = dwData["VASDABT"].ToString(); 
          or1.Parameters.Add("VASDART", OracleType.NVarChar).Value = dwData["VASDART"].ToString(); 
          or1.Parameters.Add("VASDVAR", OracleType.NVarChar).Value = dwData["VASDVAR"].ToString(); 
          or1.Parameters.Add("VASDESS", OracleType.NVarChar).Value = dwData["VASDESS"].ToString(); 
          or1.Parameters.Add("VASCOL", OracleType.NVarChar).Value = dwData["VASCOL"].ToString(); 
          or1.Parameters.Add("VASFFARBE", OracleType.NVarChar).Value = dwData["VASFFARBE"].ToString(); 
          or1.Parameters.Add("VASBESCH", OracleType.NVarChar).Value = dwData["VASBESCH"].ToString(); 
          or1.Parameters.Add("VASZUSTAND", OracleType.NVarChar).Value = dwData["VASZUSTAND"].ToString(); 
          or1.Parameters.Add("VASKZ", OracleType.NVarChar).Value = dwData["VASKZ"].ToString(); 
          or1.Parameters.Add("VASPRIO", OracleType.NVarChar).Value = dwData["VASPRIO"].ToString(); 
          or1.Parameters.Add("VASBESTD", OracleType.NVarChar).Value = dwData["VASBESTD"].ToString(); 
          or1.Parameters.Add("VASDATUM", OracleType.NVarChar).Value = dwData["VASDATUM"].ToString(); 
          or1.Parameters.Add("VASBEMERK", OracleType.NVarChar).Value = dwData["VASBEMERK"].ToString(); 
          or1.Parameters.Add("VGPFILLER", OracleType.NVarChar).Value = dwData["VGPFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
